#pragma once

#include "../common/singleton.h"
#include <map>
#include "base_outputer.h"
#include <mutex>
#include <atomic>

class OutPutManager
{
    typedef void (BaseOutputer::*Handler)(const char*);

    DECLARE_SINGLETON_CLASS(OutPutManager);
public:
    OutPutManager();
    ~OutPutManager();

    void AddOnlyOutPuter(BaseOutputer *outputer);
    void AddOutPuter(BaseOutputer *outputer);
    void RemoveOutPuter(int key);

    void DoHandler(Handler pfun, const char* result, unsigned int type = UNKNOWN_TYPE_VALID_FLAG_INDEX);

    void SetValidFlag(unsigned int valid_flag);
    unsigned int GetValidFlag();
private:
    std::map<int, BaseOutputer*> m_all_outputer;
    std::mutex m_mutex;

    std::atomic<unsigned int> m_valid_flag;
};

typedef pattern::singleton<OutPutManager> sln_output_manager;